package com.example.doudizhu;

import java.util.*;
import java.util.function.Consumer;

public class PokerGame2 {//new该对象表示开始一局游戏


    static HashMap<Integer, String> hm = new HashMap<>();
    static ArrayList<Integer> list = new ArrayList<>();

    //生成牌堆
    static {
        Integer count = 1;
        String[] color = {"♠", "♥", "♣", "♦"};
        String[] num = {"3,", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        for (String n : num) {
            for (String col : color) {
                hm.put(count, col + n);
                list.add(count);
                count++;
            }
        }
        hm.put(count, "小王");
        list.add(count);
        count++;
        hm.put(count, "大王");
        list.add(count);
    }


    public PokerGame2() {
        //洗牌
        Collections.shuffle(list);
        //发牌
        TreeSet<Integer> lord = new TreeSet<>();
        TreeSet<Integer> player1 = new TreeSet<>();
        TreeSet<Integer> player2 = new TreeSet<>();
        TreeSet<Integer> player3 = new TreeSet<>();

        for (int i = 0; i < list.size(); i++) {
            Integer temp = list.get(i);
            if (i <= 2) lord.add(temp);
            else {
                if (i % 3 == 0) player1.add(temp);
                else if (i % 3 == 1) {
                    player2.add(temp);
                } else {
                    player3.add(temp);
                }
            }
        }
        //看牌
        lookpoker("底牌", lord);
        lookpoker("玩家1", player1);
        lookpoker("玩家2", player2);
        lookpoker("玩家3", player3);

    }

    void lookpoker(String name, TreeSet<Integer> pokers) {
        System.out.print(name + " :");
        pokers.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer s) {
                String tep = hm.get(s);
                System.out.print(tep + " ");
            }
        });
        System.out.println();
    }

}
